
<#include "/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">       
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton onkeyBtn" iconCls="glyphicon-exclamation-sign" plain="true" onclick="onkeyAdd()">一键创建所有</a>
            <!-- <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">新增托盘</a> -->
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">放入物料</a>
            <!-- <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除托盘</a> -->
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <!--<a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a>
            <a href="javascript:void(0)" class="easyui-linkbutton importBtn" iconCls="glyphicon-import" plain="true" onclick="importCsv()">导入</a> -->
        </div>
    </div>
    

<script type="text/javascript">
var datagrid = $("#dg");
var loc_id = "${loc_id!}";
var tp_tnum = "${tp_tnum!}";
var param = {"locId": loc_id};
var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
        rownumbers:true,
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 40,
    	pagination:true,
    	multiSort:true,
        queryParams: param,        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'tp_no', title: '编号', width:50, sortable: true}
	           	 ,{field:'mat_no', title: '物料编码', width:120, sortable: true}
	           	 ,{field:'mat_name', title: '物料名称', width:120, sortable: true}
	           	 ,{field:'realid', title: '每盘唯一条码', width:120, sortable: true}
	           	 ,{field:'mat_num', title: '物料数量', width:70, sortable: true}
	           	 ,{field:'pro_date', title: '生产日期', width:120, sortable: true}
	           	 ,{field:'in_time', title: '存入时间', width:120, sortable: true}
	           	 ,{field:'out_time', title: '离库时间', width:120, sortable: true}
	           	 ,{field:'create_user', title: '操作人员', width:70, sortable: true}
	           	 ,{field:'of_loc', title: '所属库位', width:70, sortable: true}
	           	 ,{field:'storage_name', title: '所属仓库', width:100, sortable: true}
	           ]]
	};
$(function() {
	handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});


function onkeyAdd() {	
	dgOptions.pageSize=1000;
	dgOptions.pagination=false;
 	//如果无数据，则显示一键生成
 	var rows =datagrid.datagrid("getRows"); 
 	
	if(rows.length == 0) {
		setTrayBatch();
	}
	else {
	  showMsg("托盘有数据，不能一键生成！");	
	}
}

//一键生成托托盘
function setTrayBatch() {	
			param["tp_tnum"] = tp_tnum;
			$.post("setTrayBatch",param, function() {
				$(".easyui-linkbutton onkeyBtn").linkbutton("disable");
				showMsg("生成成功！");
				datagrid.datagrid("reload");
			});
}

function add() {
	var rows =datagrid.datagrid("getRows"); 
	//判断是否超过托盘数量，否则不能新增托盘
	if(rows.length<tp_tnum){
			top.window.subPage.loadCurrDatagrid = function() {
				showMsg("增加成功！");
				datagrid.datagrid("load");
			}
			top.openWindow("托盘信息表-增加", getCurrUrl("addPage") + "?" + $.param(param), {size: '600x300'});
		}
	else{
		showMsg("超过托盘数，请勿增加！");
	}
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("托盘信息表-编辑", getCurrUrl("updatePage") + "?id=" + id+"&"+ $.param(param), {size: '600x500'});
}

function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据！");
		return;
	}
	confirmMsg("确认删除？", function() {
		$.post("delete", {id: ids}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("reload");
		});
	});
}

function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.openWindow("托盘信息表-详情", getCurrUrl("detailPage") + "?id=" + id, {size: '600x400'});
}

function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}
function importCsv() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("导入成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("托盘信息表-导入", getCurrUrl("importCsvPage") + "?" + $.param(initPara), {size: '600x500'});
}
//按钮事件

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
dgOptions.singleSelect=true;
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
